package com.llx.producer;

import com.llx.domain.User;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @version 1.0
 * @description
 * @author viki
 * @date 2021/8/20 19:04
 */
public class SimpleProducer {
    public static void main(String[] args) {
        // 1. 加载配置⽂件
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("classpath:applicationContext-simple-producer.xml");
        // 2. 从spring容器中获取rabbitTemplate对象
        RabbitTemplate rabbitTemplate = (RabbitTemplate)
                context.getBean("rabbitTemplate");
        // 3. 准备User对象
        User user =new User(110,"张三",12);
        User user1 =new User(120,"张三",12);
        User user2 =new User(130,"张三",12);
        /*convertAndSend(参数1，参数2)
         * 参数1： 队列名称
         * 参数2： 数据
         */
        rabbitTemplate.convertAndSend("simple-queue",user);
        rabbitTemplate.convertAndSend("simple-queue",user1);
        rabbitTemplate.convertAndSend("simple-queue",user2);
        // 如果需要程序停⽌，那么我们关闭容器即可
        context.close();
    }
}
